//== SAGITTARIUS ============================================================================

//== FILEDOC =========================================================================

/** @file hashtable_nth.h
  * @brief Non-thread safe hash table
  */

//== BEGINNING OF CODE ===============================================================

#ifndef __SAGUTTARUIS__HASHTABLE_NTH__H_
#define __SAGUTTARUIS__HASHTABLE_NTH__H_

//== INCLUDES ========================================================================

#include "sagittarius/core/SagittariusCore.h"
#include <stddef.h>

#define HASH_COLLISION 1
#define HASH_SUCCESS   0

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
    uint64 k;
    void* v;
    size_t len;
} hashkv_pair64_nth;

//hashkv_pair makehashkv_pair64_nth(void* p, size_t len);

typedef struct {
    uint32 n;
    uint32 depth;
    hashkv_pair64_nth* e;
} hashbucket64_nth;

typedef struct {
    uint64 nbuckets;
    hashbucket64_nth* buckets;
} hashtable64_nth;

void* _ht64_nth_get(hashtable64_nth* ht, hashkv_pair64_nth e);
void* ht64_nth_get(hashtable64_nth* ht, void* p, size_t len);

int _ht64_nth_check(hashtable64_nth* ht, hashkv_pair64_nth e);
int ht64_nth_check(hashtable64_nth* ht, void* p, size_t len);

int _ht64_nth_insert(hashtable64_nth* ht, hashkv_pair64_nth e);
int ht64_nth_insert(hashtable64_nth* ht, void* p, size_t len, size_t copy_len);

hashtable64_nth* ht64_nth_rehash(hashtable64_nth* ht, uint32 nbuckets, uint32 depth);

//hashtable* create_hashtable(uint32 nbuckets, uint32 depth);

void ht64_nth_destroy(hashtable64_nth* h);

void ht64_nth_dumpstate(int fd, hashtable64_nth* h);

#ifdef __cplusplus
}//extern "C"
#endif

#endif
